package com.six.firstpage.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.six.core.entity.Notice;
import com.six.firstpage.service.NoticeService;
import com.six.firstpage.mapper.NoticeMapper;
import com.six.firstpage.vo.NoticeVo;
import com.six.firstpage.vo.SearchTime;
import org.springframework.beans.NotWritablePropertyException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Wrapper;
import java.util.Date;
import java.util.List;

/**
* @author ZZH
* @description 针对表【acl_notice】的数据库操作Service实现
* @createDate 2023-02-27 10:21:18
*/
@Service
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice>
    implements NoticeService{

    @Autowired
    private NoticeMapper noticeMapper;


    @Override
    public List<Notice> getAllNotice() {
        QueryWrapper<Notice> wrapper = new QueryWrapper<>();
        wrapper.eq("is_deleted",0);

        List<Notice> notices = noticeMapper.selectList(wrapper);
        return notices;
    }

    @Override
    public IPage<NoticeVo> getNoticeByTime(NoticeVo noticeVo, Integer current, Integer pageSize) {
        IPage<NoticeVo> noticePage = new Page<>(current, pageSize);

        if (noticeVo.getSearchDate()!=null && noticeVo.getSearchDate().length!=0){
            noticeVo.setBeginDate(noticeVo.getSearchDate()[0]);
            noticeVo.setEndDate(noticeVo.getSearchDate()[1]);
        }
        noticeMapper.findAllNotice(noticeVo, noticePage);


        return noticePage;
    }

    @Override
    public Integer addNotice(Notice notice) {
        notice.setGmtCreate(new Date());
        notice.setGmtModified(new Date());
        return noticeMapper.insert(notice);
    }

    @Override
    public Integer updateNotice(Notice notice) {
        notice.setGmtModified(new Date());
        return noticeMapper.updateById(notice);
    }

    @Override
    public Integer delNotice(Integer id) {
        UpdateWrapper<Notice> wrapper = new UpdateWrapper<>();
        wrapper.eq("id",id);
        wrapper.set("is_deleted",1);
        return noticeMapper.update(null, wrapper);
    }
}




